<template>
    <div class="form-container">
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">硕士学位申请系统</el-breadcrumb-item>
            <el-breadcrumb-item>答辩结果</el-breadcrumb-item>
        </el-breadcrumb>
        <h2>答辩结果</h2>
        <el-form ref="form" :model="form" label-width="180px" class="form">
            <el-form-item label="答辩委员会出席人数" prop="committee_size">
                <el-input v-model="form.committee_size" auto-complete="off"></el-input>
            </el-form-item>

            <el-form-item label="答辩时间" prop="defense_date">
                <el-date-picker v-model="form.defense_date" type="date" placeholder="选择日期">
                </el-date-picker>
            </el-form-item>

            <el-form-item label="同意授予学位票数" prop="pass_degree_number">
                <el-input v-model="form.pass_degree_number" auto-complete="off"></el-input>
            </el-form-item>

            <el-form-item label="不同意授予学位票数" prop="refusal_degree_number">
                <el-input v-model="form.refusal_degree_number" auto-complete="off"></el-input>
            </el-form-item>

            <el-form-item label="是否授予学位弃权票数" prop="abstention_degree_number">
                <el-input v-model="form.abstention_degree_number" auto-complete="off"></el-input>
            </el-form-item>

            <el-form-item label="答辩委员会答辩结论" prop="defence_conclusion">
                <el-radio-group v-model="form.defence_conclusion">
                    <el-radio label="1">同意</el-radio>
                    <el-radio label="2">缓讨论</el-radio>
                    <el-radio label="3">不同意</el-radio>

                </el-radio-group>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import axios from "axios";
// import {mapState} from "vuex";

export default {
    data() {
        return {
            form: {
                student_id: '',
                committee_size: "",
                defense_date: "",

                pass_degree_number: "",
                refusal_degree_number: "",
                abstention_degree_number: "",

                defence_conclusion: "",

                remarks: "",
            },
            pickerOptions: {
                disabledDate(time) {
                    return time.getTime() > Date.now();
                },
                shortcuts: [
                    {
                        text: "今天",
                        onClick(picker) {
                            picker.$emit("pick", new Date());
                        },
                    },
                    {
                        text: "昨天",
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24);
                            picker.$emit("pick", date);
                        },
                    },
                    {
                        text: "一周前",
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit("pick", date);
                        },
                    },
                ],
            },
        };
    },
    methods: {
        submitForm() {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    // TODO: 提交表单数据

                }
            });
        },
        resetForm() {
            this.$refs.form.resetFields();
        },
    },
    computed: {
        // ...mapState("user", ["token"]),
    },
    created() {
        axios({
            method: 'GET',
            url: 'http://localhost:8081/api/user/info?identity=' + 0 + '&token=' + this.token
        }).then(response => {

            this.form.student_id = response.data.data.student_id

            console.log(this.form.student_id)
            axios({
                method: 'GET',
                url: 'http://localhost:8081/api/defenseRes/get/51255906666'
            }).then(response => {
                console.log(response.data.data)

                this.form.committee_size = response.data.data.defense_num
                this.form.defense_date = response.data.data.defense_time
                this.form.refusal_degree_number = response.data.data.disagree
                this.form.abstention_degree_number = response.data.data.giveUp
                this.form.pass_degree_number = response.data.data.agree
                if (this.form.pass_degree_number > this.form.refusal_degree_number) {
                    this.form.defence_conclusion = '1'
                } else if (this.form.pass_degree_number < this.form.refusal_degree_number) {
                    this.form.defence_conclusion = '3'
                } else {
                    this.form.defence_conclusion = '2'
                }

            })


        })


    }


};
</script>

<style scoped>
/* .form-container {
    display: flex;
    justify-content: center;
  } */
.form {
    margin-top: 20px;
    width: 95%;
}
</style>
